package com.controller;

import com.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/studentController")
public class StudentController {
    @RequestMapping("/students")
    @ResponseBody
//    public List<Student> getAll(){
//        System.out.println("getAll123123");
//        List<Student> students = Arrays.asList(new Student[]{new Student("0901", "张三"), new Student("0901", "李四"),
//                new Student("0901", "王二")});
//        return students;
//    }


    public ModelAndView getAll(){
        System.out.println("getAll1");
        List<Student> students = Arrays.asList(new Student[]{new Student("0901", "张三"), new Student("0901", "李四"),
                new Student("0901", "王二")});
        //modelandview就是 数据和视图的组合，也就是由model 和 view
        //model 相当于request。setAttribute
        ModelAndView mv = new ModelAndView();
        mv.addObject("students",students);//添加model就是添加attribute
        mv.setViewName("/back/student/list");
        return mv;
    }
}
